<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>源辰-浏览新闻信息</title>
<link rel="shortcut icon" href="../../images/copylogo.png" type="image/x-icon" />
<link rel="stylesheet" href="../css/common.css">
<link rel="stylesheet" href="../css/main.css">
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript">
var pageNo = 1;
var pageSize = 10;
var totalSize = 0;
var totalPage = 0;

$(function(){
	$.post("handle/donews.php", {op:"getNewsInfoByFirstPage", pageNo:pageNo, pageSize:pageSize}, function(data) {
		data = JSON.parse(data);
		totalSize = data.total;
		totalPage = Math.ceil(totalSize / pageSize);
		
		var pageInfo = '<li class="first-child active"><a href="javascript:void()" onclick="findByPage(this, 1)">首页</a></li>';
		pageInfo += '<li class="active"><a href="javascript:void()" onclick="findByPage(this, 1)">1</a></li>';
		for (var i = 2; i <= totalPage; i ++) {
			pageInfo += '<li><a href="javascript:void()" onclick="findByPage(this, ' + i + ')">' + i +'</a></li>';
		}
		pageInfo += '<li class="last-child"><a href="javascript:void()" onclick="findByPage(this, ' + totalPage + ')">末页</a></li>';
		
		$("#pagination_info").append($(pageInfo));
		
		var str = "";
		$.each(data.rows, function(index, item) {
			str += "<tr><td>" + item.nid + "</td><td>" + item.title + "</td><td>" + item.author + "</td><td>" + item.ndate + "</td><td>" + item.tname 
			+ "</td><td>" + item.views + "</td><td><a href=''>[修改]</a>&nbsp;&nbsp;<a href=''>[删除]</a>&nbsp;&nbsp;<a href=''>[查看]</a></td></tr>";
		});
		$("#news_info").append($(str));
	}, "json");
});

function findByPage(obj, page) {
	pageNo = page;
	$.post("handle/donews.php", {op:"findByPage", pageNo:pageNo, pageSize:pageSize}, function(data) {
		data = JSON.parse(data);
		var str = "";
		$.each(data, function(index, item) {
			str += "<tr><td>" + item.nid + "</td><td>" + item.title + "</td><td>" + item.author + "</td><td>" + item.ndate + "</td><td>" + item.tname 
			+ "</td><td>" + item.views + "</td><td><a href=''>[修改]</a>&nbsp;&nbsp;<a href=''>[删除]</a>&nbsp;&nbsp;<a href=''>[查看]</a></td></tr>";
		});
		$("#news_info").html("").append($(str));
		
		$("#pagination_info>li").removeClass("active");
		$(obj).parent().addClass("active");
	}, "json");
}

</script>
</head>
<body>
<div id="table" class="mt10">
	<div class="box span10 oh">
		<table width="100%" border="0" cellpadding="0" cellspacing="0" class="list_table">
			<thead>
				<tr>
					<th width="80">新闻编号</th>
                   	<th width="200">新闻标题</th>
                   	<th width="100">新闻作者</th>
                   	<th width="120">发布日期</th>
                   	<th width="50">新闻类型</th>
                   	<th width="50">浏览次数</th>
                   	<th width="120">操作</th>
                </tr>
             </thead>
             <tbody id="news_info" align="center">
				<tr>
					<td>1001</td>
					<td>源辰信息开班了</td>
					<td>源辰</td>
					<td>2018-12-12</td>
					<td>国内</td>
					<td>10000</td>
					<td><a href=''>[修改]</a>&nbsp;&nbsp;<a href=''>[删除]</a>&nbsp;&nbsp;<a href=''>[查看]</a></td>
				</tr>
             </tbody>
		</table>
        <div class="page mt10">
		<div class="pagination">
            <ul id ="pagination_info">
				<li class="first-child active"><a href="javascript:void()" onclick=" ">首页</a></li>
				<li class="active"><a href="javascript:void()" onclick=" ">1</a></li>
				<li><a href="javascript:void()" onclick=" ">2</a></li>
				<li class="last-child"><a href="javascript:void()" onclick=" ">末页</a></li>'
			</ul>
		</div>
        </div>
	</div>
</div>
</body>
</html>